package com.mpj.yolov12

import android.content.Context
import android.net.wifi.WifiManager

open class WifiHelper {
    private var wifiManager: WifiManager? = null
    private var multicastLock: WifiManager.MulticastLock? = null

    companion object {
        val instance: WifiHelper by lazy { WifiHelper() }
    }

    /**
     * 碰到一台华为meta50设备接收不到UDP广播
     * 原因：厂商定制默认将该功能关闭
     * 华为手机或者说是harmonyos 手机系统存在兼容问题，在华为手机上，udp广播监听会失败，所以这里使用udp广播监听器来监听广播
     */

    open fun openWifiManager(context: Context) {
        wifiManager = context.getSystemService(Context.WIFI_SERVICE) as WifiManager
        multicastLock = wifiManager!!.createMulticastLock("222")
        //在调用receive
        multicastLock!!.acquire()
    }

    open fun releaseWifiManager() {
        multicastLock?.release()
    }

}